/*
 * UVFrame.java
 *
 * Created on 5 October 2008, 11:51
 */

package uvtray;

import java.text.SimpleDateFormat;

/**
 *
 * @author  Simon
 */
public class UVFrame extends javax.swing.JFrame {

    private SimpleDateFormat dateFormat
            = new SimpleDateFormat("d MMM yyyy hh:mm aaa");
    
    /** Creates new form UVFrame */
    public UVFrame() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        updatePanel = new javax.swing.JPanel();
        updateButton = new javax.swing.JButton();
        updateLabel = new javax.swing.JLabel();
        dataPanel = new javax.swing.JPanel();
        dataComboBox = new javax.swing.JComboBox();
        dataLabel = new javax.swing.JLabel();
        title = new javax.swing.JLabel();
        info = new javax.swing.JLabel();

        setTitle("UVTray");
        setAlwaysOnTop(true);
        setName("uvframe"); // NOI18N
        setResizable(false);

        updatePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Update"));

        updateButton.setText("Update Now");
        updateButton.setEnabled(false);

        updateLabel.setText("<html>Last update:<br>Next Update:</html>");

        javax.swing.GroupLayout updatePanelLayout = new javax.swing.GroupLayout(updatePanel);
        updatePanel.setLayout(updatePanelLayout);
        updatePanelLayout.setHorizontalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, updatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(updateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(updateButton)
                .addContainerGap())
        );
        updatePanelLayout.setVerticalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, updatePanelLayout.createSequentialGroup()
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(updateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(updateButton)))
                .addContainerGap())
        );

        dataPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Data"));

        dataComboBox.setEnabled(false);

        dataLabel.setText("Updating...");

        javax.swing.GroupLayout dataPanelLayout = new javax.swing.GroupLayout(dataPanel);
        dataPanel.setLayout(dataPanelLayout);
        dataPanelLayout.setHorizontalGroup(
            dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dataPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dataLabel, javax.swing.GroupLayout.Alignment.LEADING, 332,332,332)//javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                    .addComponent(dataComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, 332, 332))//Short.MAX_VALUE))
                .addContainerGap())
        );
        dataPanelLayout.setVerticalGroup(
            dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataPanelLayout.createSequentialGroup()
                .addComponent(dataLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(dataComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        title.setFont(new java.awt.Font("Tahoma", 1, 18));
        title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        title.setText("Bureau of Meteorology UV Alerter");
        title.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        info.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        info.setText("<html><center>Copyright © 2008 - Simon Windows<br>Relased under the GPL v3.0<br>UV Data from the Bureau of Meteorology</center></html>");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(updatePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(title, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(info, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(dataPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(title)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(info)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(updatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dataPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox dataComboBox;
    private javax.swing.JLabel dataLabel;
    private javax.swing.JPanel dataPanel;
    private javax.swing.JLabel info;
    private javax.swing.JLabel title;
    private javax.swing.JButton updateButton;
    private javax.swing.JLabel updateLabel;
    private javax.swing.JPanel updatePanel;
    // End of variables declaration//GEN-END:variables

    /** Adds an action listener to handle the update button and combo box
     * 
     * @param l The action listener to be added.
     */
    public void addActionListener(java.awt.event.ActionListener l) {
        updateButton.addActionListener(l);
        dataComboBox.addActionListener(l);
        updateButton.setEnabled(true);
        dataComboBox.setEnabled(true);
    }
    
    /** Sets a model for the location selecter combo box
     * 
     * @param model A list of locations for the combo box.
     */
    public void setModel(javax.swing.ComboBoxModel model)
    {
        dataComboBox.setModel(model);
    }

    /** Changes the text in the update box label.
     * 
     * @param text The new label text.
     */
    public void setUpdateText(long last, long next)
    {
          updateLabel.setText("<html>Last update: " + dateFormat.format(last) +
                "<br>Next update: " + dateFormat.format(next) + "</html>");
    }
    
    /** Changes the text in the data box label.
     * 
     * @param text The new label text.
     */
    public void setDataText(String text)
    {
        dataLabel.setText(text);
    }
    
    /*
     * Todo: class creation should require event handlers for UpdateNow and
     * ChangeLocation. Methods should be provided to update the locations list
     * (including *none* to grey it out), UV Alert data and next update time.
     * show/hide are inherited from JFrame
     */

}
